package com.dimples.dd.common.result;

import com.dimples.dd.common.core.IMsgCode;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 自定义响应码
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2024/6/6
 */
@ToString
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IMsgCode, Serializable {

    SUCCESS_SMS_CALLBACK("0", "成功"),

    SUCCESS("000000", "一切ok"),
    SYSTEM_EXECUTION_ERROR("000001", "系统执行出错"),
    GATEWAY_EXECUTION_ERROR("000002", "网关异常"),

    VALIDATE_CODE_NOT_NULL("000003", "请输入验证码"),
    VALIDATE_CODE_EXPIRED("000004", "验证码已过期"),
    VALIDATE_CODE_ERROR("000005", "验证码不正确"),

    GATEWAY_TOKEN_ERROR("000503", "请通过网关获取资源"),

    URL_FORBID_ERROR("000403", "该URI不允许外部访问"),

    AUTH_LOGIN_BAD_CREDENTIALS("000100", "登录失败，账号密码不正确"),
    AUTH_LOGIN_USER_DISABLED ("000101", "登录失败，账号被禁用"),
    AUTH_LOGIN_CAPTCHA_CODE_ERROR("000102", "验证码不正确，原因：{}"),
    AUTH_THIRD_LOGIN_NOT_BIND ("000103", "未绑定账号，需要进行绑定"),
    AUTH_TOKEN_EXPIRED ("000104", "Token 已经过期"),
    AUTH_MOBILE_NOT_EXISTS ("000105", "手机号不存在"),
    TOKEN_EXPIRED("000230", "token已过期"),
    TOKEN_INVALID("000330", "token无效"),
    TOKEN_REFRESH_ERROR("000340", "刷新token时未解析到请求参数, 请求参数应该放于form-data中"),
    TOKEN_PARSE_USER_ID_ERROR("000231", "token中为解析到用户Id信息"),
    ACCESS_UNAUTHORIZED("000301", "访问未授权"),
    FORBIDDEN_OPERATION("000302", "演示环境禁止新增、修改和删除重要数据，请本地部署后测试"),
    REPEAT_SUBMIT_ERROR("000303", "您的请求已提交，请不要重复提交或等待片刻再尝试。"),

    PARAM_ERROR("000400", "用户请求参数错误"),
    RESOURCE_NOT_FOUND("000401", "请求资源不存在"),
    PARAM_IS_NULL("000410", "请求参数缺失"),

    FLOW_LIMITING("000429", "请求太频繁咯！"),

    DATABASE_ERROR("000300", "数据库服务出错"),

    DATA_NOT_FOUND("000301", "数据不存在"),

    REQUEST_PATH_DUPLICATION("000500", "重复定义了相同的映射关系: {}"),

    ;

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private String code;

    private String msg;


    public static ResultCode getValue(String code) {
        for (ResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SYSTEM_EXECUTION_ERROR; // 默认系统执行错误
    }
}
